<?php

namespace app\common\model;
use app\common\model\User;
class SignedLog extends BaseModel
{
    protected $name = 'signed_log';

    /**
     * 新增变更记录 (批量)
     * @param $data
     * @return array|false
     * @throws \Exception
     */
    public function records($saveData)
    {
        return $this->isUpdate(false)->saveAll($saveData);
    }
    /**
     * 签送日志
     * @throws \think\exception\DbException
     */
    public function handleSingled(){
        $list = User::all();
        $saveData = [];
        if(!empty($list)){
            foreach ($list as $item){
                $data['user_id'] = $item->user_id;
                $data['last_date'] = date('Y-m-d',strtotime('last month'));
                $data['old_signed_amount'] = $item->signed_amount;
                $data['now_date'] = date('Y-m-d',time());
                $data['change_signed_amount'] = $item->signed_set_amount;
                $data['wxapp_id'] = 10012;
                $item->signed_amount = $item->signed_set_amount;
                $result = $item->save();
                if($result){
                    echo json_encode($data)."\r\n";
                }
                $saveData[] = $data;
            }
            $this->records($saveData);
        }
        exit();
    }
}